﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Quartz;
using Wicresoft.fjyc.Integration.Engine;

namespace FJHost.Tasks
{
    class UFSSybase : IJob
    {
        private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
        public void Execute(IJobExecutionContext context)
        {
            var datas = context.JobDetail.JobDataMap;

            string command = (string)datas["command"];
            string date = (string)datas["date"];

            string paramss = string.Empty;



            log.Info("Start Sybase(" + command + "(" + paramss + "))    Date:" + DateTime.Now.ToString());

            DateTime timestamp;
            bool isDate = false;
            if (DateTime.TryParse(date, out timestamp))
            {
                paramss = date;
                isDate = true;
            }
            if (string.Equals("1", date))
            {
                paramss = DateTime.Now.AddDays(-1).ToShortDateString();
                isDate = true;
            }

            log.Info(paramss);

            try
            {
                if (isDate)
                {
                    SybaseTest.Task.Excute(new string[] { paramss });
                }
            }
            catch (Exception e)
            {
                log.Error(e.Message, e);
            }

            log.Info("Start Sybase(" + command + "(" + paramss + "))    Date:" + DateTime.Now.ToString());

            //CMD.Run(command, paramss);

            log.Info("End Sybase(" + command + "(" + paramss + "))    Date:" + DateTime.Now.ToString());
        }
    }
}
